// screeps相关api
import axios from '.'
import {
    IMarketOrder,
    INuke,
    IPvp,
    IRoomAreaInfo,
    IRoomObjects,
    IUser,
    IUserRank,
    Shard,
} from '../interface/screeps.interface'

// 房间相关api

/**
 * 获取正在发生pvp的房间
 * @param interval 时间间隔
 */
export const getActivePvpRoom = (interval = 10) => {
    if (interval < 10 || interval < 100) interval = 10
    return axios.get<IPvp>('/experimental/pvp', {
        params: {
            interval,
        },
    })
}

/**
 * 查看核弹信息
 */
export const getNuke = () => {
    return axios.get<INuke>('/experimental/nukes')
}

/**
 * 查看一个房间地区信息
 * @param room 房间名
 * @param shard 分片
 */
export const getRoomAreaInfo = (room: string, shard: Shard) => {
    return axios.get<IRoomAreaInfo>('/game/room-status', {
        params: {
            room,
            shard,
        },
    })
}

/**
 * 查看房间对象
 * @param room 房间名
 * @param shard 分片
 */
export const getRoomObject = (room: string, shard: Shard) => {
    return axios.get<IRoomObjects>('/game/room-objects', {
        params: {
            room,
            shard,
        },
    })
}

// 用户相关api

/**
 * 查看指定用户的信息
 * @param username 用户名
 */
export const getUserInfo = (username: string) => {
    return axios.get<IUser>('/user/find', {
        params: {
            username,
        },
    })
}

// 市场相关api

/**
 * 获取市场订单信息
 * @param resource 资源名
 * @param shard 分片
 */
export const getMarketOrderInfo = (resourceType: string, shard: Shard) => {
    return axios.get<IMarketOrder>('/game/market/orders', {
        params: {
            resourceType,
            shard,
        },
    })
}

// 排名相关api

/**
 * 获取指定用户排名
 * @param mode 排名模式
 * @param username 用户名
 * @returns
 */
export const getRank = async (mode: string, username: string) => {
    return axios.get<IUserRank>('/leaderboard/find', {
        params: {
            mode,
            username,
        },
    })
}
